import {Component, Input} from '@angular/core';
import { ViewController } from 'ionic-angular';
import {EditorService} from "../../services/EditorService";
import {EmojiService} from "../../services/EmojiService";

@Component({
    templateUrl: 'emoji-popover-page.html',
    providers: [EditorService, EmojiService],
})
export class EmojiPopoverPage {

  emojis: any = {};
  category: string = 'people';
  @Input()
  emojiInputName: string = '';

  constructor(public viewCtrl: ViewController, private editorService: EditorService, private emojiService: EmojiService) {
    if (viewCtrl.data.emojiInputName !== '')
    {
      this.emojiInputName = viewCtrl.data.emojiInputName;
      editorService.registerEmojiInput(this.emojiInputName);
    }
    emojiService.getEmojiList().then(list => {
      this.emojis = list;
    })
  }

  insertEmoji(emoji_id: string)
  {
    if (this.emojiInputName !== '')
    {
      this.editorService.sendEmoji(this.emojiInputName, emoji_id);
    }
  }

  close() {
    this.viewCtrl.dismiss();
  }
}
